home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / Venus / mars < prev    next >
Internet Message Format  |  1994-05-17  |  8KB

  1. From oauld@ponder Sun Apr 10 14:48:00 1994
  2. Resent-From: "John Booth    " <JOHN@gab.unt.edu>
  3. Resent-To: oleg@ponder
  4. Resent-Date:   Sun, 10 Apr 1994 14:47:31 CST6CDT
  5. Date: Sat, 26 Mar 94 12:19:31 -0600
  6. From: oauld@ponder (Orion Auld)
  7. To: john@gab.unt.edu, elliott@ponder
  8. Subject: Mars demo guts
  9. Status: OR
  10.  
  11. >Newsgroups: rec.games.programmer
  12. >Path: news.unt.edu!cs.utexas.edu!swrinde!emory!news-feed-2.peachnet.edu!concert!hearst.acc.Virginia.EDU!murdoch!usenet
  13. >From: cp5m@hagar16.Virginia.EDU (Colin  Prepscius)
  14. >Subject: Re: Recursive Map Generation
  15. >Date: Fri, 25 Mar 1994 00:44:59 GMT
  16.  
  17. In article <bhacking-240394155643@bhacking.npd.provo.novell.com>  
  18. bhacking@novell.com (Brian Hacking) writes:
  19. > In article <2mq013$fln@usenet.rpi.edu>, taherm@vccnorth16.its.rpi.edu
  20. > (Marwan Taher) wrote:
  21. > > Also, in his paper Tim suggested 'blurring' the map with:
  22. > >     w(u,v)=k1*w(u,v)+k2*(u+3,v-2)+k3*w(u-2,v+4)
  23. > > where k1+k2+k3=1. ( w(u,v) contains the height of point at coords  
  24. (u,v). )
  25. > I and several other readers missed this post on Mars guts.  Can someone
  26. > report it or email it to me????  Puhlease....
  27. > *** These are my words, not Novell's ***
  28.  
  29. Here ya go.  I asked the same thing about 2 weeks ago.  Note - corrections  
  30. to this (below) were also posted - basically just replace r w/ q in the  
  31. following sentence...
  32. line of map from v=r+100 (say) down to v=r, do this:
  33.  
  34. --
  35. !@#$%^&*()_++_)(*&^%$#@!
  36.  
  37. Colin Prepscius
  38. cp5m@broca.med.virginia.edu
  39. homephone:804-295-2108
  40. labphone:804-924-0356
  41.  
  42.  
  43. *****************************************
  44.  
  45.  
  46.         Voxel landscapes and How I did it
  47.         ---------------------------------
  48.  
  49.  This document describes the method I used in my demo of a Martian  
  50. terrain,
  51. which can be found at garbo.uwasa.fi:/pc/demo/mars10.zip.
  52.  It's similar to a floating horizon hidden line removal algorithm, so  
  53. you'll
  54. find discussion of the salient points in many computer graphics books. The
  55. difference is the vertical line interpolation.
  56.  
  57.  
  58. First, some general points:
  59. ---------------------------
  60.  
  61.  The map is a 256x256 grid of points, each having and 8-bit integer
  62. height and a colour. The map wraps round such that, calling w(u,v) the
  63. height at (u,v), then
  64. w(0,0)=w(256,0)=w(0,256)=w(256,256). w(1,1)=w(257,257), etc.
  65.  
  66.  Map co-ords: (u,v) co-ordinates that describe a position on the
  67. map. The map can be thought of as a height function w=f(u,v) sampled
  68. discretely.
  69.  
  70.  Screen co-ords: (x,y) co-ordinates for a pixel on the screen.
  71.  
  72.  
  73. To generate the map:
  74. --------------------
  75.  
  76.  This is a recursive subdivision, or plasma, fractal. You start of
  77. with a random height at (0,0) and therefore also at (256,0), (0,256),
  78. (256,256).  Call a routine that takes as input the size and position
  79. of a square, in the first case the entire map.
  80.  This routine get the heights from the corners of the square it gets
  81. given.  Across each edge (if the map has not been written to at the
  82. point halfway along that edge), it takes the average of the heights of
  83. the 2 corners on that edge, applies some noise proportional to the
  84. length of the edge, and writes the result into the map at a position
  85. halfway along the edge. The centre of the square is the average of the
  86. four corners+noise.
  87.  The routine then calls itself recursively, splitting each square into
  88. four quadrants, calling itself for each quadrant until the length of
  89. the side is 2 pixels.
  90.  This is probably old-hat to many people, but the map is made more
  91. realistic by blurring:
  92.  
  93.      w(u,v)=k1*w(u,v)+k2*w(u+3,v-2)+k3*w(u-2,v+4) or something.
  94.  
  95.  Choose k1,k2,k3 such that k1+k2+k3=1. The points at which the map is
  96. sampled for the blurring filter do not really matter - they give
  97. different effects, and you don't need any theoretical reason to choose
  98. one lot as long as it looks good. Of course do everything in fixed
  99. point integer arithmetic.
  100.  The colours are done so that the sun is on the horizon to the East:
  101.  
  102.      Colour=A*[ w(u+1,v)-w(u,v) ]+B
  103.  
  104. with A and B chosen so that the full range of the palette is used.
  105.  The sky is a similar fractal but without the colour transformation.
  106.  
  107.  
  108. How to draw each frame
  109. ----------------------
  110.  
  111.  First, draw the sky, and blank off about 50 or so scan lines below
  112. the horizon since the routine may not write to all of them (eg. if you
  113. are on top of a high mountain looking onto a flat plane, the plane
  114. will not go to the horizon).
  115.  Now, down to business. The screen is as follows:
  116.  
  117.      ---------------------------
  118.      |                         |
  119.      |                         |
  120.      |           Sky           |
  121.      |                         |
  122.      |                         |
  123.      |a------------------------| Horizon
  124.      |                         |
  125.      |                         |    Point (a)=screen co-ords (0,0)
  126.      |          Ground         |     x increases horizontally
  127.      |                         |     y increases downwards
  128.      |                         |
  129.      ---------------------------
  130.  
  131.  Imagine the viewpoint is at a position (p,q,r) where (p,q) are the
  132. (u,v) map co-ordinates and r is the altitude. Now, for each horizontal
  133. (constant v) line of map from v=r+100 (say) down to v=r, do this:
  134.  
  135.   1. Calculate the y co-ordinate of map co-ord (p,v,0) (perspective  
  136. transform)
  137.  
  138.   2. Calculate scale factor f which is how many screen pixels high a
  139. mountain of constant height would be if at distance v from
  140. q. Therefore, f is small for map co-ords far away (v>>q) and gets
  141. bigger as v comes down towards q.
  142.  
  143.   3. Work out the map u co-ord corresponding to (0,y). v is constant
  144. along each line.
  145.  
  146.   4. Starting at the calculated (u,v), traverse the screen,
  147. incrementing the x co-ordinate and adding on a constant, c, to u such
  148. that (u+c,v) are the map co-ords corresponding to the screen co-ords
  149. (1,y). You then have 256 map co-ords along a line of constant v. Get
  150. the height, w, at each map co-ord and draw a spot at (x,y-w*f) for all
  151. x.
  152.  
  153.  Sorry, but that probably doesn't make much sense. Here's an example:
  154. Imagine sometime in the middle of drawing the frame, everything behind
  155. a point (say v=q+50) will have been drawn:
  156.  
  157.      ---------------------------
  158.      |                         |
  159.      |                         |
  160.      |                         |
  161.      |           ****          |
  162.      |        *********        | <- A mountain half-drawn.
  163.      |-----**************------|
  164.      |*************************|
  165.      |*********       *********|
  166.      |******             ******|
  167.      |.........................| <- The row of dots is at screen co-ord y
  168.      |                         |   corresponding to an altitude of 0 for  
  169. that
  170.      ---------------------------   particular distance v.
  171.  
  172.  Now the screen-scanning routine will get called for v=q+50. It draws
  173. in a point for every x corresponding to heights at map positions (u,v)
  174. where u goes from p-something to p+something, v constant. The routine
  175. would put points at these positions: (ignoring what was there before)
  176.  
  177.      ---------------------------
  178.      |                         |
  179.      |                         |
  180.      |                         |
  181.      |                         |
  182.      |                         |
  183.      |-------------------------|
  184.      |          *****          |
  185.      |       ***     ***       |
  186.      |*******           *******|
  187.      |.........................|
  188.      |                         |
  189.      ---------------------------
  190.  
  191.  So, you can see that the screen gets drawn from the back, one
  192. vertical section after another. In fact, there's more to it than
  193. drawing one pixel at every x during the scan - you need to draw a
  194. vertical line between (x,y old) to (x,y new), so you have to have a
  195. buffer containing the y values for every x that were calculated in the
  196. previous pass. You interpolate along this line (Gouraud style) from
  197. the old colour to the new colour also, so you have to keep a buffer of
  198. the colours done in the last pass.
  199.  Only draw the vertical lines if they are visible (ie. going down, y
  200. new>y old). The screen is drawn from the back so that objects can be
  201. drawn inbetween drawing each vertical section at the appropriate time.
  202.  
  203.  If you need further information or details, mail me or post here...
  204. Posting will allow others to benefit from your points and my replies,
  205. though.
  206.  
  207.  Thank you for the response I have received since uploading this program.
  208.  
  209.  Tim Clarke, tjc1005@hermes.cam.ac.uk
  210.  
  211.  
  212.